<?php


namespace LazadaApi\Services;


use function Sodium\add;

class LazadaLogisticsService extends BaseLazadaService
{
    /**
     * 卖家调用api 获取新的 lzd_bag 编号
     *
     * @see https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.2c3d6bbe6GdZ0B#/api?cid=6&path=/logistics/lzd_bag/get
     * @return mixed
     * @throws \Exception
     */
    public function getNewBagNumber()
    {
        return $this->get('/logistics/lzd_bag/get');
    }

    /**
     * 使用此API获取所有可用的运输提供商的列表，使用SetStatusToPackedByMarketplace API时需要此列表
     *
     * @see https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.2c3d6bbe6GdZ0B#/api?cid=6&path=/shipment/providers/get
     */
    public function getShipmentProviders()
    {
        return $this->get('/shipment/providers/get');
    }

    /**
     * 卖方发布跟踪号，并获取相对于跟踪号的包裹状态
     *
     * @see https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.2c3d6bbe6GdZ0B#/api?cid=6&path=/logistics/package/query
     *
     * @param array $trackingNumbers ["dvTRS789x","tr2","tr3"]
     *
     * @return mixed
     * @throws \Exception
     */
    public function queryPackageStatus(array $trackingNumbers)
    {
        $this->addApiParam('tracking_numbers', $trackingNumbers);

        return $this->post('/logistics/package/query');
    }

    /**
     * 1. 卖家使用此api进行发布Lazada行包裹编号和相对跟踪编号
     * 2. Api返回lzd_bag_number
     *
     * @see https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.2c3d6bbe6GdZ0B#/api?cid=6&path=/logistics/lzd_bag/upload
     *
     * @param array  $trackingNumbers ["tr1","tr2","tr3"]
     * @param string $erpBagNumber    EPR123-345
     * @param int    $parcelsTotal    3
     * @param string $lzdBagNumber    L190801-5123-00002  通过getNewBagNumber获取
     *
     * @return mixed
     * @throws \Exception
     */
    public function uploadLazadaBagNumber(array $trackingNumbers, string $erpBagNumber, int $parcelsTotal, string $lzdBagNumber)
    {
        $this->addApiParam('tracking_numbers', $trackingNumbers);
        $this->addApiParam('erp_bag_number', $erpBagNumber);
        $this->addApiParam('parcels_total', $parcelsTotal);
        $this->addApiParam('lzd_bag_number', $lzdBagNumber);

        return $this->post('/logistics/lzd_bag/upload');
    }

    /**
     * 1. 卖家使用此api进行发布卖家的lzd_bag_number 和相对应的 tracking_numbers
     * 2. Api返回lzd_bag_number
     *
     * @see https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.2c3d6bbe6GdZ0B#/api?cid=6&path=/logistics/seller_bag/upload
     *
     * @param array  $trackingNumbers ["tr1","tr2","tr3"]
     * @param string $erpBagNumber    erptestbag2
     * @param int    $parcelsTotal    3
     *
     * @return mixed
     * @throws \Exception
     */
    public function uploadSellerBagNumber(array $trackingNumbers, string $erpBagNumber, int $parcelsTotal)
    {
        $this->addApiParam('tracking_numbers', $trackingNumbers);
        $this->addApiParam('erp_bag_number', $erpBagNumber);
        $this->addApiParam('parcels_total', $parcelsTotal);

        return $this->post('/logistics/seller_bag/upload');
    }
}